<template>
  <el-card class="category">
    <el-form :inline="true" class="demo-form-inline" :disabled="!disabledSelector">
      <el-form-item label="一级分类">
        <!-- <el-select v-model="categorySelectorInfoStore.category1Id" placeholder="请选择"> -->
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option :label="c1.name" :key="c1.id" v-for="c1 in categorySelectorInfoStore.category1List" :value="c1.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option :label="c2.name" v-for="c2 in categorySelectorInfoStore.category2List" :value="c2.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option :label="c3.name" v-for="c3 in categorySelectorInfoStore.category3List" :value="c3.id" />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts">
export default {
  name: 'CategorySelector'
};
</script>


<script lang="ts" setup>
import { onMounted, reactive, computed, defineProps } from 'vue';
import { useCategorySelectorInfoStore } from '@/stores/categorySelector';
defineProps(['disabledSelector']);
const categorySelectorInfoStore = useCategorySelectorInfoStore();

onMounted(() => {
  categorySelectorInfoStore.getCategory1ListData();
});

const category1Id = computed({
  get() {
    return categorySelectorInfoStore.category1Id as number;
  },
  set(val: number) {
    // console.log(val)
    // categorySelectorInfoStore.category1Id = val
    // 调用方法 获取对应的二级分类数据
    categorySelectorInfoStore.getCategory2ListData(val);
  }
});

const category2Id = computed({
  get() {
    return categorySelectorInfoStore.category2Id as number;
  },
  set(val: number) {
    categorySelectorInfoStore.getCategory3ListData(val);
  }
});

const category3Id = computed({
  get() {
    return categorySelectorInfoStore.category3Id as number;
  },
  set(val: number) {
    categorySelectorInfoStore.setCategory3Id(val);
  }
});
</script>

<style lang="scss" scoped>
.category {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>